package com.mapper;

import com.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    // 查询所有用户
    @Select("select * from user;")
    List<User> selectAllUsers();

    // id 查询一个用户
    @Select("select * from user where userId = #{userId};")
    User selectOneUserById(int id);

    // name 查询用户
    @Select("select * from user where username like '%${username}%';")
    List<User> selectUsersByName(String name);

    // id 删除一个用户
    @Delete("delete from user where userId = #{userId};")
    int deleteOneUserById(int id);

    // 新增一个用户
    @Insert("insert into user (username) values (#{username});")
    int insertOneUserById(User user);

    // 修改一个用户
    @Insert("update user set username = #{username} where userId = #{userId};")
    int updateOneUserById(User user);
}
